document.write('<script language=javascript src="js/jquery-3.5.1.min.js"></script>');
//document.write('<script language=javascript src="js/jquery-3.6.0.min.js"></script>');
document.write('<link rel="stylesheet" href="css/register.css">');
$(function (){
    $('#username').on('blur',function (){
        $.ajax({
            type    : "GET",
            url     : "usernameExist?username="+this.value,
            success : function (data){
                if(data.code===2){
                    $('#usernameTips').attr("class","invalid").text("输入不可为空");//样式
                }else if(data.code===1){
                    $('#usernameTips').attr("class","invalid").text("用户名不存在，请您先注册！");
                }else{
                    $('#usernameTips').attr("class","invalid").text("");
                }

            }
        });
    });
});
$(function (){
    $('#password').on('blur',function (){
        $.ajax({
            type    : "GET",
            url     : "match?username="+document.getElementById("username").value+"&password="+this.value,
            success : function (data){
                if(data.code===8){
                    $('#passwordTips').attr("class","invalid").text("密码错误");//样式
                }else if(data.code===9){
                    $('#passwordTips').attr("class","invalid").text("输入不可为空");
                }else if(data.code===10){
                    $('#passwordTips').attr("class","invalid").text("");
                }
            }
        });
    });
});
/*
$(function (){
    $('#vCode').on('blur',function (){
        $.ajax({
            type    : "GET",
            url     : "checkCode?vCode="+this.value,
            success : function (data){
                if(data.code===3){
                    //验证码框未输入
                    $('#vCodeTips').attr("class","invalid").text("输入不可为空");
                }else if(data.code===4){
                    $('#vCodeTips').attr("class","available").text("验证码正确");
                }else if(data.code===5){
                    $('#vCodeTips').attr("class","invalid").text("验证码错误");
                }
            }
        });
    });
});
*/
$(function (){
    $('#signon').on('click',function (){
        var result;
        var result1;
        $.ajax({
            type    : "GET",
            url     : "match?username="+document.getElementById("username").value+"&password="+document.getElementById("password").value,
            success : function (data){
                if(data.code===10){
                    result=1;
                    $.ajax({
                        type    : "GET",
                        url     : "checkCode?vCode="+document.getElementById("vCode").value,
                        success : function (data){
                            if(data.code===4){
                                result1=1;
                                if(result==1&&result1==1){
                                    console.log("123456")
                                    $('#signonTips').attr("class","invalid").text("");
                                    var formElement = document.forms[1];
                                    formElement.submit();
                                }else{
                                    $('#signonTips').attr("class","invalid").text("登陆失败");
                                }
                            }else{
                                $('#signonTips').attr("class","invalid").text("登陆失败");
                            }
                        }
                    });
                }else{
                    $('#vCodeTips').attr("class","invalid").text("验证码错误");
                }
            }
        });
    });
});